package com.css.fxfzxczh.modules.eqDisasterLossAssess.houseFinishLossAssess.repository.impl;

import com.css.fxfzxczh.modules.eqDisasterLossAssess.houseFinishLossAssess.entity.HouseFinishDamageLossRatio;
import com.css.fxfzxczh.modules.eqDisasterLossAssess.houseFinishLossAssess.repository.HouseFinishDamageLossRatioRepository;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author:
 * @CreateTime: 2023/8/9 10:14
 * @Description:
 */
@Repository
public class HouseFinishDamageLossRatioRepositoryImpl implements HouseFinishDamageLossRatioRepository {


    @Resource
    JdbcTemplate jdbcTemplate;
    @Resource
    NamedParameterJdbcTemplate namedParameterJdbcTemplate;

    @Override
    public void houseFinishDlRatioUpdate(HouseFinishDamageLossRatio entity) {
        String sql="update xczh_house_finish_damage_loss_ratio set loss_ratio1=:lossRatio1," +
                "loss_ratio2=:lossRatio2,loss_ratio3=:lossRatio3,loss_ratio4=:lossRatio4,loss_ratio5=:lossRatio5," +
                "loss_ratio6=:lossRatio6,loss_ratio7=:lossRatio7,loss_ratio8=:lossRatio8,loss_ratio9=:lossRatio9," +
                "loss_ratio10=:lossRatio10,update_user=:updateUser," +
                "update_time=:updateTime " +
                " where xhfdlr_id=:xhfdlrId ";
        SqlParameterSource source = new BeanPropertySqlParameterSource(entity);
         namedParameterJdbcTemplate.update(sql, source);
    }

    @Override
    public void houseFinishDlRatioSave(HouseFinishDamageLossRatio entity) {
        String sql="insert into xczh_house_finish_damage_loss_ratio(xhfdlr_id,xsem_id,xsem_name,loss_ratio1,loss_ratio2," +
                "loss_ratio3,loss_ratio4,loss_ratio5,loss_ratio6,loss_ratio7,loss_ratio8,loss_ratio9,loss_ratio10," +
                "del_flag,create_user,create_time,extends1,extends2,extends3) " +
                "values(:xhfdlrId,:xsemId,:xsemName,:lossRatio1,:lossRatio2," +
                ":lossRatio3,:lossRatio4,:lossRatio5,:lossRatio6,:lossRatio7,:lossRatio8,:lossRatio9,:lossRatio10," +
                ":delFlag,:createUser,:createTime,:extends1,:extends2,:extends3)";
        SqlParameterSource source = new BeanPropertySqlParameterSource(entity);
         namedParameterJdbcTemplate.update(sql, source);
    }

    @Override
    public HouseFinishDamageLossRatio getHouseFinishDlRatioByXsemId(String xsemId) {
        String sql="select * from xczh_house_finish_damage_loss_ratio where xsem_id = ?  and del_flag='0'";
        List<HouseFinishDamageLossRatio> query = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(HouseFinishDamageLossRatio.class), xsemId);
        return query.size()<1?null:query.get(0);
    }
}
